package com.example.coffee.slice;

import com.example.coffee.ResourceTable;
import com.example.coffee.items.OrderItem;
import com.example.coffee.mock.DataMockManager;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Image;
import ohos.agp.components.Text;

public class OrderSlice extends AbilitySlice {

    OrderItem orderItem;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_order_slice);
        requestData(intent.getStringParam("id"));
        setup();
    }

    private void requestData(String id) {
        orderItem = DataMockManager.mockOrderDetail(id);
    }

    private void setup() {
        Text statusText = (Text) findComponentById(ResourceTable.Id_order_status);
        statusText.setText(orderItem.getStatus());

        Image image = (Image) findComponentById(ResourceTable.Id_order_image);
        image.setPixelMap(orderItem.getCaffeeItem().getImageId());
        image.setCornerRadius(20);

        Text idText = (Text) findComponentById(ResourceTable.Id_order_id);
        idText.setText("订单编号：" + orderItem.getOrderId());

        Text nameText = (Text) findComponentById(ResourceTable.Id_order_p_name);
        nameText.setText(orderItem.getCaffeeItem().getName());

        Text descText = (Text) findComponentById(ResourceTable.Id_order_p_desc);
        descText.setText(orderItem.getCaffeeItem().getDescription());

        Text priceText = (Text) findComponentById(ResourceTable.Id_order_p_price);
        priceText.setText(orderItem.getCaffeeItem().getPrice());

        Text totalPriceText = (Text) findComponentById(ResourceTable.Id_order_total);
        totalPriceText.setText("总计：" + orderItem.getTotalPriec());

        Text timeText = (Text) findComponentById(ResourceTable.Id_order_time);
        timeText.setText("订单时间：" + orderItem.getCreateTime());

        Text phoneText = (Text) findComponentById(ResourceTable.Id_order_phone);
        phoneText.setText("商家电话：" + orderItem.getPhoneNumber());
    }
}
